/****************************************************
    ScriptName:        test.cs
    Author:            摸鱼程序男
    CreatTime:    2020/12/14 14:19:48
    Description:     Nothing
*****************************************************/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
using DG.Tweening;
using System.Linq;
using BTAI;
using ZYKTool;


namespace HQL
{

    

    public abstract class BossBase : MonoBehaviour
    {
        //public bool 让boss直接死 = false;
        protected bool _IsAttack = false;
        protected SpriteRenderer _SR;
        protected Color _MyColor;
        protected Root _aiRoot = BT.Root();
        public float _Blood;
       // public bool canCall;
        protected GameObject _Player;
        protected int 当前阶段 = 1;
        [HideInInspector]
        public bool _Is中毒 = false;
        protected BossName BossName;
        protected bool _已经死亡 = false;
        protected AudioSource _AudioSource;

        private bool _isInit = false;
        public virtual void Init()
        {
            _AudioSource = transform.GetOrAddComponent<AudioSource>();
            _Player = TapTapStaticValue.Player;
            _isInit = true;
        }
        protected abstract void Attack();
        public virtual void 换阶段()
        {
            当前阶段++;
        }

         protected void PlaySound(int index=1)
        {
            string name="";
            if(index==1)
            {
                name = "BOSS技能释放";
            }
            else
            {
                name = "死亡音效";
            }
         AudioClip clip = Resources.Load<AudioClip>(name);
            _AudioSource.clip = clip;
            _AudioSource.PlayOneShot(clip);
         }
    private void OnEnable()
        {
           // Init();
        }
        public abstract void BossHunt(float damage);

        private void Update()
        {
            if(_isInit)
            //  Debug.LogError(_已经死亡);
            _aiRoot.Tick();
        }

        public Root GetAIRoot()
        {
            return _aiRoot;
        }

        float _timer = 3;
        protected float _AttackTimer;
        protected bool _AttackOver = true;
        protected virtual bool CanAttack()
        {
            if (!_AttackOver) return false;//每次攻击结束才开始计时

            if (_timer > _AttackTimer)//计时
            {
                _AttackOver = false;
                //Debug.LogError(111);
                _timer = 0;
                return true;
            }
            _timer += Time.deltaTime;
            return false;
        }
        protected void OnTriggerEnter2D(Collider2D other)
        {
            if (other.tag == "Player")
            {
                TapTapStaticValue.TapTapModelManger.Damage(BossName.None, 2);
            }
        }
        protected void Die(BossName bossName)
        {
          _已经死亡 = true;
            TapTapStaticValue.BossAttributes[BossName].Blood = 0;
        TapTapStaticValue.BossAttributes.Remove(bossName);
            Destroy(gameObject);
            //todo:贺启亮 死亡之后干嘛？？？
        }
    }
}